package controller.admin;

import java.io.Serializable;

import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;

import persistence.ProfileDAO;

import dto.search.ProfileDTO;
import entity.Profile;

@ManagedBean(name = "profileController")
@SessionScoped
public class ProfileController implements Serializable {

	private static final long serialVersionUID = -9203081431637325103L;

	public Integer addProfile(ProfileDTO profileDTO) throws Exception {
		ProfileDAO dao=new ProfileDAO();
		return dao.persist(copyProperties(profileDTO));

	}

	public void editProfile(ProfileDTO profileDTO) throws Exception {
		ProfileDAO dao=new ProfileDAO();
		dao.merge(copyProperties(profileDTO));
	}

	public void deleteProfile(ProfileDTO profileDTO) throws Exception {
		ProfileDAO dao=new ProfileDAO();
		dao.remove(copyProperties(profileDTO));
	}
	
	private Profile copyProperties(ProfileDTO profileDTO){
		Profile profile=new Profile();
		profile.setAboutself(profileDTO.getAboutself());
		profile.setAddress(profileDTO.getAddress());
		profile.setAge(profileDTO.getAge());
		profile.setBirthplace(profileDTO.getBirthplace());
		profile.setComplexion(profileDTO.getComplexion());
		profile.setDob(profileDTO.getDob());
		profile.setEducation(profileDTO.getEducation());
		profile.setEducationlevel(profileDTO.getEducationlevel());
		profile.setEmail(profileDTO.getEmail());
		profile.setFathername(profileDTO.getFathername());
		profile.setFatherprofession(profileDTO.getFatherprofession());
		profile.setFirstname(profileDTO.getFirstname());
		profile.setGender(profileDTO.getGender());
		profile.setHeight(profileDTO.getHeight());
		profile.setIncome(Double.parseDouble(profileDTO.getIncome()));
		profile.setIdProfile(profileDTO.getIdProfile());
		profile.setLastname(profileDTO.getLastname());
		profile.setMaritalstatus(profileDTO.getMaritalstatus());
		profile.setMaternalgotram(profileDTO.getMaternalgotram());
		profile.setMobileno(profileDTO.getMobileno());
		profile.setMothername(profileDTO.getMothername());
		profile.setMotherprofession(profileDTO.getMotherprofession());
		profile.setOccupation(profileDTO.getOccupation());
		profile.setPaternalgotram(profileDTO.getPaternalgotram());
		profile.setRasi(profileDTO.getRasi());
		profile.setStar(profileDTO.getStar());
		profile.setTenantid(profileDTO.getTenantid());
		profile.setReccrtts(profileDTO.getReccrtts());
		profile.setReclstupdatets(profileDTO.getReclstupdatets());
		return profile;
	}
}
